// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2022 Huawei Technologies Co., Ltd */
#ifndef HIUDK_SDK_CRM_H
#define HIUDK_SDK_CRM_H

#if defined(HIUDK_SDK_ADPT) && defined(HIUDK_SDK)

#include "hinic3_crm.h"

static inline int sdk_alloc_ceqs(void *udkdev, enum hinic3_service_type type,
				 int num, int *ceq_id_array, int *act_num)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_alloc_ceqs(sdk_hwdev, type, num, ceq_id_array, act_num);
}

static inline int sdk_alloc_irqs(void *udkdev, enum hinic3_service_type type,
				 u16 num, struct irq_info *irq_info_array, u16 *act_num)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_alloc_irqs(sdk_hwdev, type, num, irq_info_array, act_num);
}

static inline u8 sdk_ceq_num(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_ceq_num(sdk_hwdev);
}

static inline int sdk_cos_valid_bitmap(void *udkdev, u8 *func_dft_cos, u8 *port_cos_bitmap)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_cos_valid_bitmap(sdk_hwdev, func_dft_cos, port_cos_bitmap);
}

static inline u8 sdk_ep_id(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_ep_id(sdk_hwdev);
}

static inline u8 sdk_er_id(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_er_id(sdk_hwdev);
}

static inline void sdk_fault_event_report(void *udkdev, u16 src, u16 level)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_fault_event_report(sdk_hwdev, src, level);
}

static inline u8 sdk_flexq_en(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_flexq_en(sdk_hwdev);
}

int sdk_get_fake_vf_info(void *udkdev, u8 *fake_vf_vld, u8 *page_bit, u8 *pf_start_bit, u8 *map_host_id)
{
	void *sdk_hwdev = NULL;
 
	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}
 
	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_get_fake_vf_info(sdk_hwdev, fake_vf_vld, page_bit, pf_start_bit, map_host_id);
}

static inline u32 sdk_host_pf_num(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_host_pf_num(sdk_hwdev);
}

static inline u32 sdk_host_pf_id_start(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_host_pf_id_start(sdk_hwdev);
}

static inline void sdk_free_ceq(void *udkdev, enum hinic3_service_type type, int ceq_id)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_free_ceq(sdk_hwdev, type, ceq_id);
}

static inline void sdk_free_irq(void *udkdev, enum hinic3_service_type type, u32 irq_id)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_free_irq(sdk_hwdev, type, irq_id);
}

static inline u16 sdk_func_max_nic_qnum(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_func_max_nic_qnum(sdk_hwdev);
}

static inline u16 sdk_func_max_qnum(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_func_max_qnum(sdk_hwdev);
}

static inline u16 sdk_func_max_vf(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_func_max_vf(sdk_hwdev);
}

static inline int sdk_func_rx_tx_flush(void *udkdev, u16 channel)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_func_rx_tx_flush(sdk_hwdev, channel, true);
}

static inline enum func_type sdk_func_type(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_func_type(sdk_hwdev);
}

static inline int sdk_get_card_present_state(void *udkdev, bool *card_present_state)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_get_card_present_state(sdk_hwdev, card_present_state);
}

static inline int sdk_get_chip_present_flag(const void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_get_chip_present_flag(sdk_hwdev);
}

static inline int sdk_get_fw_version(void *udkdev, struct hinic3_fw_version *fw_ver, u16 channel)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_get_fw_version(sdk_hwdev, fw_ver, channel);
}

static inline u32 sdk_get_heartbeat_status(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return 0;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_get_heartbeat_status(sdk_hwdev);
}

static inline int sdk_get_mgmt_version(void *udkdev, u8 *mgmt_ver, u8 version_size, u16 channel)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_get_mgmt_version(sdk_hwdev, mgmt_ver, version_size, channel);
}

#define hinic3_alloc_ceqs   sdk_alloc_ceqs
#define hinic3_alloc_irqs   sdk_alloc_irqs
#define hinic3_ceq_num   sdk_ceq_num
#define hinic3_cos_valid_bitmap   sdk_cos_valid_bitmap
#define hinic3_ep_id   sdk_ep_id
#define hinic3_er_id   sdk_er_id
#define hinic3_fault_event_report   sdk_fault_event_report
#define hinic3_flexq_en   sdk_flexq_en
#define hinic3_get_fake_vf_info   sdk_get_fake_vf_info
#define hinic3_host_pf_num sdk_host_pf_num
#define hinic3_host_pf_id_start sdk_host_pf_id_start
#define hinic3_free_ceq   sdk_free_ceq
#define hinic3_free_irq   sdk_free_irq
#define hinic3_func_max_qnum   sdk_func_max_qnum
#define hinic3_func_max_vf   sdk_func_max_vf
#define hinic3_func_rx_tx_flush   sdk_func_rx_tx_flush
#define hinic3_func_type   sdk_func_type
#define hinic3_get_card_present_state   sdk_get_card_present_state
#define hinic3_get_chip_present_flag   sdk_get_chip_present_flag
#define hinic3_get_fw_version   sdk_get_fw_version
#define hinic3_get_heartbeat_status   sdk_get_heartbeat_status
#define hinic3_get_mgmt_version   sdk_get_mgmt_version

#endif
#endif
